package com.tancire.web.controller.app;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.net.domain.AuthDetail;
import com.tancire.net.domain.OrderInfo;
import com.tancire.net.service.IOrderInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单管理Controller
 *
 * @author chenchao
 * @date 2023-11-29
 */
@RestController
@RequestMapping("/net/app/order")
public class OrderAppController extends BaseController {
    @Resource
    private IOrderInfoService orderInfoService;

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('net:user:union')")
    @Log(title = "下单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OrderInfo orderInfo) {
        return toAjax(orderInfoService.addOrder(orderInfo));
    }

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('net:user:union')")
    @Log(title = "使用", businessType = BusinessType.INSERT)
    @PostMapping("/use")
    public AjaxResult use(@RequestBody AuthDetail authDetail) {
        return AjaxResult.success("获取成功", orderInfoService.useOrder(authDetail));
    }

    /**
     * 查询当前会员订单列表
     */
    @PreAuthorize("@ss.hasPermi('net:user:union')")
    @GetMapping("/delete/{orderId}")
    public AjaxResult delete(@PathVariable("orderId") Long orderId) {
        this.orderInfoService.deleteOrderInfoById(orderId);
        return AjaxResult.success("订单删除成功");
    }

    /**
     * 查询当前会员订单列表
     */
    @PreAuthorize("@ss.hasPermi('net:user:union')")
    @GetMapping("/list")
    public TableDataInfo list(OrderInfo orderInfo) {
        startPage();
        List<OrderInfo> list = orderInfoService.selectUserOrderList(orderInfo);
        return getDataTable(list);
    }

}
